﻿namespace A14_Ex06_Noam_300476694_Shai_300380698
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;

    public enum eSquareStatus
    {
        Empty,
        Player1,
        Player2
    }

    public class Cell
    {
        private eSquareStatus m_SquareStatus;
        private ePlayerSymbol? m_Symbol;

        public event Action<ePlayerSymbol?> m_onChangeDelegate;

        public Cell()
        {
            m_SquareStatus = eSquareStatus.Empty;
            m_Symbol = null;
        }

        public ePlayerSymbol? PlayerSymbol
        {
            get { return m_Symbol; }
        }

        public eSquareStatus SquareStatus 
        {
            get { return m_SquareStatus; }
            set 
            { 
                m_SquareStatus = value;
                setSymbolBySquareStatus();

                if (m_onChangeDelegate != null)
                {
                    m_onChangeDelegate.Invoke(PlayerSymbol);
                }
            }
        }

        public void InitCell()
        {
            SquareStatus = eSquareStatus.Empty;
        }

        private void setSymbolBySquareStatus()
        {
            switch (m_SquareStatus)
            {
                case eSquareStatus.Empty:
                    m_Symbol = null;
                    break;
                case eSquareStatus.Player1:
                    m_Symbol = ePlayerSymbol.X;
                    break;
                case eSquareStatus.Player2:
                    m_Symbol = ePlayerSymbol.O;
                    break;
                default:
                    m_Symbol = null;
                    break;
            }
        }
    }
}
